<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DataType class</title>
<link rel="stylesheet" href="../qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js"></script>
<script type="text/javascript" src="../qunit/qunit.js"></script>
<script type="text/javascript" src="../../javascript/DataType.class.js"></script>
<script type="text/javascript" src="../../javascript/global.js"></script>
<script type="text/javascript" src="../../javascript/util.js"></script>
<script type="text/javascript">
var xhrs = []; 
	
function callXHR(mode){
    var url = '/o-my-friends/ajax/getFriendsDataAJAX.php?mode=' + mode;
    return $.getJSON(url, null, function(response){
        trace2("callback");
		trace2(xhrs["1"].responseText);
    });
}
	
var flags = {
    "ONEWAY_MESSAGE_FLAG" : 1,
    "TWOWAY_MESSAGE_FLAG" : 2,
    "MY_POST_FLAG" : 4,
    "FRIEND_POST_FLAG" : 8,
    "MY_COMMENT_ON_STATUS_FLAG" : 16,
    "MY_COMMENT_ON_LINK_FLAG" : 32,
    "MY_COMMENT_ON_NOTE_FLAG" : 64,
    "MY_COMMENT_ON_PHOTO_FLAG" : 128,
    "FRIEND_COMMENT_ON_STATUS_FLAG" : 256,
    "FRIEND_COMMENT_ON_LINK_FLAG" : 512,
    "FRIEND_COMMENT_ON_NOTE_FLAG" : 1024,
    "FRIEND_COMMENT_ON_PHOTO_FLAG" : 2048,
    "MY_LIKE_ON_STATUS_FLAG" : 4096,
    "MY_LIKE_ON_LINK_FLAG" : 8192,
    "MY_LIKE_ON_NOTE_FLAG" : 16384,
    "MY_LIKE_ON_PHOTO_FLAG" : 32768,
    "FRIEND_LIKE_ON_STATUS_FLAG" : 65536,
    "FRIEND_LIKE_ON_LINK_FLAG" : 131072,
    "FRIEND_LIKE_ON_NOTE_FLAG" : 262144,
    "FRIEND_LIKE_ON_PHOTO_FLAG" : 524288
};

module("DataType Test Suite");

test("initialize", function(){
	var flag = "MY_POST_FLAG";
	const DEFAULT_WEIGHT = 1;
	var datatype = new DataType(flag, flags[flag], DEFAULT_WEIGHT);
	
	equal(datatype.name, flag);
	equal(datatype.flag, flags[flag]);
	equal(datatype.weight, DEFAULT_WEIGHT);
	equal(datatype.isLoaded, false);
	
	datatype.isLoaded = true;
	equal(datatype.isLoaded, true);
	
});	

test("dataTypes array", function(){
	var dataTypes  = [];
	for(var flag in flags){
	    var upperDataType = convertFlagToUpperDataType(flag);
	    dataTypes[flag] = new DataType(flag, flags[flag], default_weight[upperDataType]);
  
    }
	for(var flag in dataTypes){
		notEqual(dataTypes[flag].flag, null, "flag is not null");
		notEqual(dataTypes[flag].name, null, "name is not null");
		notEqual(dataTypes[flag].weight, null, "weight is not null");
	}
});

test("getjSON", function(){
	xhrs["1"] = callXHR(1);
	trace2(xhrs["1"]);
	

});

test("get loaded", function(){
	
    var dataTypes = [];
    for (var flag in flags) {
        var upperDataType = convertFlagToUpperDataType(flag);
        dataTypes[flag] = new DataType(flag, flags[flag], default_weight[upperDataType]);
        
    }
    var mode = 3;
    for (var flag in dataTypes) {
        if ((mode & dataTypes[flag].flag) == dataTypes[flag].flag) {
            dataTypes[flag].isLoaded = true;
        }
    }	
	equal(dataTypes["ONEWAY_MESSAGE_FLAG"].isLoaded, true);
	equal(dataTypes["TWOWAY_MESSAGE_FLAG"].isLoaded, true);
});
</script>
</head>
<body>
    <h1 id="qunit-header">QUnit Test Suite</h1>
    <h2 id="qunit-banner"></h2>
    <div id="qunit-testrunner-toolbar"></div>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture">test markup</div>
</body>
</html>